﻿'Written By Sean Molenaar
'0.1.0 Alpha tests only butane
'0.2.0 integrating my old quiz into the form
'0.2.5 finaly got it to work
'0.3.0 all the alkanen work
'0.3.2 got alkenen as wel now
'0.9.5 got options as wel as a main menu now
'1.0.0 everithing's coded and up for first alpha

Public Class frmAlkane
    Private good3 As String
    Private good2 As String
    Private b As String() = System.IO.File.ReadAllLines("good.txt")
    Private question2 As Integer
    Private question As Double
    Private highscore As String
    Private nummer As Double
    Private good As String
    Private wrong As String
    Private ans1 As String
    Private ans2 As String
    Private ans3 As String
    Private ans4 As String
    Private ans5 As String
    Private ans6 As String
    Private ans7 As String
    Private ans8 As String
    Private ans9 As String
    Private invul As String
    Private fcr As System.IO.FileStream
    Private g As String() = System.IO.File.ReadAllLines("good.txt")
    Private f As String() = System.IO.File.ReadAllLines("wrong.txt")
    Private s As String() = System.IO.File.ReadAllLines("question.txt")
    Private a As String() = System.IO.File.ReadAllLines("highscore.txt")
    Dim ResourceFilePathPrefix As String

    Private Sub frmAlkanen_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        question = 1
        nummer = 0
        question2 = question
        txtRatio.Text = good / wrong
        lblQuestion.Text = " "
        txtHighscore.Text = a(0)
        txtQuestion2.Text = question2
        txtFalse.Text = wrong
        txtgood.Text = good
        ans1 = "butane"
        ans2 = "octane"
        ans3 = "propane"
        ans4 = "methane"
        ans5 = "nonane"
        ans6 = "hexane"
        ans7 = "nonane"
        ans8 = "tetradecane"
        ans9 = "octadecane"
        good = g(0)
        wrong = f(0)
        lblQuestion.Text = s(question)
        txtRatio.Text = wrong / good
        txtFalse.Text = wrong
        txtgood.Text = good

        If System.Diagnostics.Debugger.IsAttached() Then
            'In Debugging mode  
            ResourceFilePathPrefix = System.IO.Path.GetFullPath(Application.StartupPath & "\..\..\resources\")
        Else
            'In Published mode  
            ResourceFilePathPrefix = Application.StartupPath & "\resources\"
        End If
    End Sub



    Public Sub DeleteLine(ByRef FileAddress As String, ByRef line As Integer)
        Dim TheFileLines As New List(Of String)
        TheFileLines.AddRange(System.IO.File.ReadAllLines(FileAddress))
        ' if line is beyond end of list the exit sub
        If line >= TheFileLines.Count Then Exit Sub
        TheFileLines.RemoveAt(line)
        System.IO.File.WriteAllLines(FileAddress, TheFileLines.ToArray)
    End Sub



    Private Sub cmbAns_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbAnswer.Click
        'begin hoofdprogramma
        If question = 10 Then
            MsgBox("dit is het einde van de alkanen")
            DeleteLine(ResourceFilePathPrefix & "good.txt", 0)
            Using sw As New IO.StreamWriter(ResourceFilePathPrefix & "good.txt")
                sw.WriteLine(good)
            End Using
            DeleteLine(ResourceFilePathPrefix & "wrong.txt", 0)
            Using sw As New IO.StreamWriter(ResourceFilePathPrefix & "wrong.txt")
                sw.WriteLine(wrong)
            End Using
        End If

        invul = txtAnswer.Text

        'text for question 2
        If question = 1 And invul <> ans1 Then
            lblError.Text = "This answer is wrong; it should be: butane"
            wrong = wrong + 1
            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "2.jpg"
        End If

        If question = 1 And invul = ans1 Then
            lblError.Text = "This answer (" + ans1 + ")is correct."
            good = good + 1
            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "2.jpg"
        End If

        'text for question 2
        If question = 2 And invul <> ans2 Then
            lblError.Text = "This answer is wrong it should be octane"
            wrong = wrong + 1

            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "3.jpg"
        End If

        If question = 2 And invul = ans2 Then
            lblError.Text = "This answer (" + ans2 + ")is correct."

            good = good + 1
            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "3.jpg"
        End If




        'text for question 3
        If question = 3 And invul <> ans3 Then
            lblError.Text = "This answer is wrong it should be propane"
            wrong = wrong + 1

            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "4.jpg"
        End If

        If question = 3 And invul = ans3 Then
            lblError.Text = "This answer (" + ans3 + ")is correct."

            good = good + 1
            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "4.jpg"
        End If




        'text for question 4
        If question = 4 And invul <> ans4 Then
            lblError.Text = "This answer is wrong it should be hethaan"
            wrong = wrong + 1

            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "5.jpg"
        End If

        If question = 4 And invul = ans4 Then
            lblError.Text = "This answer (" + ans4 + ")is correct."

            good = good + 1
            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "5.jpg"
        End If




        'text for question 5
        If question = 5 And invul <> ans5 Then
            lblError.Text = "This answer is wrong it should be nonane"
            wrong = wrong + 1

            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "6.jpg"
        End If

        If question = 5 And invul = ans5 Then
            lblError.Text = "This answer (" + ans5 + ")is correct."

            good = good + 1
            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "6.jpg"
        End If




        'text for question 6
        If question = 6 And invul <> ans6 Then
            lblError.Text = "This answer is wrong it should be hexane"
            wrong = wrong + 1

            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "7.jpg"
        End If

        If question = 6 And invul = ans6 Then
            lblError.Text = "This answer (" + ans6 + ")is correct."

            good = good + 1
            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "7.jpg"
        End If





        'text for question 7
        If question = 7 And invul <> ans7 Then
            lblError.Text = "This answer is wrong it should be nonane"
            wrong = wrong + 1

            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "8.jpg"
        End If

        If question = 7 And invul = ans7 Then
            lblError.Text = "This answer (" + ans7 + ")is correct."

            good = good + 1
            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "8.jpg"
        End If

        'text for question 8
        If question = 8 And invul <> ans8 Then
            lblError.Text = "This answer is wrong it should be tetradecane"
            wrong = wrong + 1

            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "9.jpg"
        End If

        If question = 8 And invul = ans8 Then
            lblError.Text = "This answer (" + ans8 + ")is correct."

            good = good + 1
            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "9.jpg"
        End If

        'text for question 9
        If question = 9 And invul <> ans9 Then
            lblError.Text = "This answer is wrong it should be octadecane"
            wrong = wrong + 1

            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "10.jpg"
        End If

        If question = 9 And invul = ans9 Then
            lblError.Text = "This answer (" + ans9 + ")is correct."

            good = good + 1
            pctAlkaan.ImageLocation = ResourceFilePathPrefix & "10.jpg"
        End If

        lblQuestion.Text = s(question)
        question = question + 1
        txtRatio.Text = wrong / good
        txtFalse.Text = wrong
        txtgood.Text = good
        If highscore < good Then
            DeleteLine("highscore.txt", 0)
            Using sw As New IO.StreamWriter("highscore.txt")
                sw.WriteLine(good)
            End Using
        End If

        Using sw As New IO.StreamWriter("good.txt")
            sw.WriteLine(good)
        End Using
        Using sw As New IO.StreamWriter("wrong.txt")
            sw.WriteLine(wrong)
        End Using

        'einde hoofdprogramma
    End Sub

    Private Sub cmbSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSave.Click
        DeleteLine("highscore.txt", 0)
        Using sw As New IO.StreamWriter("highscore.txt")
            sw.WriteLine(good)
        End Using
        DeleteLine("good.txt", 0)
        Using sw As New IO.StreamWriter("good.txt")
            sw.WriteLine(good)
        End Using
        DeleteLine("wrong.txt", 0)
        Using sw As New IO.StreamWriter("wrong.txt")
            sw.WriteLine(wrong)
        End Using
        Me.Hide()
    End Sub
End Class
